import store from '../store/index'
import get from '@/request/get/index.js'
import Utils from './Utils'

export default {
	data() {
		return {
			userInfo: {},
			shareTitle: "良品小程序",
			shareDesc: "良品直供，心心相印",
			imageUrl: "",
		}
	},
	onLoad: function() {
		if (uni.getStorageSync("liangpin_user_info_20241004")) {
			this.userInfo = uni.getStorageSync("liangpin_user_info_20241004");
		}


		uni.hideShareMenu({
			menus: ['shareTimeline']
		})

		wx.showShareMenu({
			withShareTicket: true,
			menus: ["shareAppMessage"]

		})
	},

	onShareAppMessage(res) {
		console.log(res);
		let that = this;

		if (res.from === 'menu') {
			var sharePath = "pages/index/index"
			if (this.userInfo.id) {
				sharePath = '/pages/index/index?inviteCode=' + this.userInfo.user.inviteCode                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
			}

			return {
				title: this.shareTitle,
				path: sharePath,
				imageUrl: this.imageUrl,

			};
		} else if (res.from === 'button') {
			sharePath = uni.getStorageSync("share_url")
			uni.removeStorageSync("share_url")
			this.imageUrl = uni.getStorageSync("share_img")
			uni.removeStorageSync("share_img")
			return {
				title: this.shareTitle,
				path: sharePath,
				imageUrl: this.imageUrl
			}
		}
	},
	// 分享到朋友圈
	onShareTimeline() {
		let that = this;
		var sharePath = "pages/index/index"
		if (this.userInfo.id) {
			sharePath = '/pages/index/index?inviteCode=' + this.userInfo.user.inviteCode
		}

		return {
			title: this.shareTitle,
			path: sharePath,
			imageUrl: this.imageUrl
		};
	},
	methods: {
		// //分享的标题和描述
		// getShareInfo() {
		// 	this.$get({
		// 		url: `${TipSettingBaseUrl}/TipSettingAjaxList`,
		// 	}).then(res => {
		// 		const {
		// 			data
		// 		} = res;
		// 		if (data.length > 0) {
		// 			var titleArr = data.filter(item => {
		// 				return item.etipSettingType == 9
		// 			})
		// 			if (titleArr.length > 0) {
		// 				var regex = /(<([^>]+)>)/ig
		// 				this.shareTitle = titleArr[0].name.replace(regex, "").replace(/#{([\s\S]*?)}/g, (_,
		// 					name) => Utils.getTemplateData(this.userInfo, name.trim()));;
		// 			}
		// 			var descArr = data.filter(item => {
		// 				return item.etipSettingType == 10
		// 			})
		// 			if (descArr.length > 0) {
		// 				var regex = /(<([^>]+)>)/ig
		// 				this.shareDesc = descArr[0].name.replace(regex, "").replace(/#{([\s\S]*?)}/g, (_,
		// 					name) => Utils.getTemplateData(this.userInfo, name.trim()))
		// 			}


		// 		}



		// 	})
		// },
		// //分享用到的图片路径
		// getBackground() {
		// 	this.$get({
		// 		url: `${BannerBaseUrl}/BannerAjaxList`,
		// 		data: {
		// 			eBannerType: 3
		// 		}
		// 	}).then(res => {
		// 		const {
		// 			data
		// 		} = res;
		// 		if (data.length > 0) {
		// 			this.imageUrl = data[0].imgUrl;
		// 		}
		// 	})
		// }
	}
}